﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Controls.DataVisualization.Charting;
using System.Windows.Data;

namespace Demos.MFSets
{
    /// <summary>
    /// Interaction logic for ChartView.xaml
    /// </summary>
    public partial class ChartView : Window
    {
        public List<KeyValuePair<int, double>>[] Valores
        {
            get { return (List<KeyValuePair<int, double>>[])GetValue(ValoresProperty); }
            set { SetValue(ValoresProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Valores.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ValoresProperty =
            DependencyProperty.Register("Valores", typeof(List<KeyValuePair<int, double>>[]), typeof(ChartView), new UIPropertyMetadata(null));


        public ChartView()
        {
            InitializeComponent();
        }

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            LoadLineChartData();
        }

        private void LoadLineChartData()
        {
            var lineaActual = 0;
            foreach (var linea in Valores)
            {
                if (mcChart.Series.Count <= lineaActual)
                {
                    break;
                }
                ((LineSeries) mcChart.Series[lineaActual]).ItemsSource = linea;
                lineaActual++;
            }
        }
    }

    class AlturaConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (double)value - 30;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
